package com.baosight.sczx.common.zm.cInterface.cc;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.iplat4j.util.NumberUtils;
import com.baosight.iplat4j.util.StringUtils;

/**
 * 质量标准化基础配置
 * <p>Title: Qualitystandard.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-29 上午09:20:57  严洪浩  Create
 *</pre>
 */
public class Qualitystandard {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 获得所有质量标准化项目
	 * <p>Function: getQualitystandardItems</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-29上午09:22:24 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static List getQualityStandardItems() {
		List  _list = new ArrayList();
		_list = dao.query("ZMCCQualitystandardItems.query", null);;
		return _list;
	}
	
	/**
	 * 获得所有质量标准化项目提供给BLOCK
	 * <p>Function: getQualitystandardItems</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-29上午09:22:24 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static EiBlock getQualityStandardItems(String eiBlockName, String fdStatus, boolean isAll) {
		EiBlock block = new EiBlock(eiBlockName);

		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		Map<String, String> _args = new HashMap<String, String>();
		_args.put("fdStatus", fdStatus);
		
		List _result = new ArrayList();
		List _list = dao.query("ZMCCQualitystandardSubitem.queryInterface", _args);
		
		if(isAll)  {
			Map<String, String> _map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("display", "");
			_result.add(_map);
			
			for(int i = 0; i < _list.size(); i++) {
				_result.add(_list.get(i));
			}
		}
		else {
			_result = _list;
		}
		
		block.setRows(_result);
		return block;
	}
	
	/**
	 * 获取总分
	 * <p>Function: getSumPoint</p>
	 * <p>Description: </p>
	 * <p>return value:float</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-30上午05:24:40 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static float getSumPoint() {
		List  _list = new ArrayList();
		_list = dao.query("ZMCCQualitystandardClassify.queryPointValue", null);;
		
		float result = 0;
		for(int i = 0; i < _list.size(); i++) {
			Map _map = (Map)_list.get(i);
			float fdClassifyPoint = NumberUtils.toFloat(StringUtils.toString(_map.get("fdClassifyPoint")));
			float fdPointValue = NumberUtils.toFloat(StringUtils.toString(_map.get("fdPointValue")));
			result += fdClassifyPoint * fdPointValue;
		}
		
		//四舍五入  保留一位小数
		BigDecimal temp = new BigDecimal(result);
		float _value = temp.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
		return _value;
	}

}
